/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package optimizacion;

import Distribuciones.Uniforme;
import ec.util.MersenneTwisterFast;

/**
 *
 * @author USUARIO
 */
public class Montecarlo {
    
    /**
     * Halla el mayor valor de Sen(x)
     * entre 0 y PI, uando en metodo montecarlo
     * @param args 
     */
    public static void main(String[] args) {
        Uniforme uniforme = new Uniforme(0D,2*Math.PI);
        MersenneTwisterFast prng = new MersenneTwisterFast(432164778);
        int n= 10000;
        double fMax = -1000;
        double xMax = 0.0;
        double xi;
        double yi;
        for (int i = 0; i < n; i++) {
            xi = uniforme.generar(prng.nextDouble());
            yi = Function.fx(xi);
            if (yi > fMax) {
                xMax = xi;
                fMax= yi;
            }
        }
        System.out.println("x maximo: " + xMax);
        System.out.println("f(x) maximo: "+ fMax);
    }
}
